<?php session_start();

echo $_POST['searchform']."<br>";

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


@mysql_select_db("progin_171_13509008", $con);
$query = "";

if(isset($_POST['byuser']) && isset($_POST['bytitletag']))
{
    $query = "select * from content where user_name = '".$_POST['searchform']."' or title = '".$_POST['searchform']."'"; 
    
}
else if(isset($_POST['byuser'])) //kalau udah dibikin berdasarkan user
{
    echo $_POST['byuser']."<br>";
    $query = "select * from content where user_name = '".$_POST['searchform']."'";   
}
else if(isset($_POST['bytitletag'])) //kalau udah dibikin berdasarkan title tag
{
    echo $_POST['bytitletag']."<br>";
    $query = "select * from content where title = '".$_POST['searchform']."'"; 
    }
else
{ echo "mohon centang masukan pilihan pencarian.";}

$result = mysql_query($query);
if(mysql_num_rows($result) == 0)
{
        echo "No result found.";
}
else
{
         echo "<script type='text/javascript' src='script/home.js'></script>";
     for($i = 0; $i < mysql_num_rows($result) ; $i++)
     {
        $row = mysql_fetch_array($result);
         if($row['content_type']== 'link'){
                        echo "<h1>".$row['title']."</h1>";
                        echo "<h2>".$row['content_filled']."</h2>";
                        echo "<h3>".$row['content_description']."</h3>";
                        echo "<h3>Posted by: <a href='detail.php'>".$row['user_name']."</a></h3>";
                    }
                    if($row['content_type']== 'image'){
                        echo "<h1>".$row['title']."</h1>";
                        echo "<img src='".$row['content_filled']."' height=500px; ></img>";
                        echo "<h3>Posted by: <a href='detail.php'>".$row['user_name']."</a></h3>";
                    }
                    if($row['content_type']== 'video'){
                        echo "<h1>".$row['title']."</h1>";
                        echo $row['content_filled'];
                        echo "<h3>Posted by: <a href='detail.php'>".$row['user_name']."</a></h3>";
                    }
                   echo"<script type='text/javascript'>"; //hitung nilai like dan dislike dulu!
                   echo "likeUpdater(".$row['id_content']."); dislikeUpdater(".$row['id_content'].");";
                   echo "</script>";
                   
                   echo"<input id='like_".$row['id_content']."' class='like_button' type='image' src='images/like_button.jpg' onclick='like(\"".$_SESSION['user_name']."\",".$row['id_content'].")'/>";
                   echo"<input class='total_like_class' type='text' disabled='disabled' id='total_like_".$row['id_content']."' />";
                   echo"<input id='dislike_'".$row['id_content']." class='like_button' type='image' src='images/dislike_button.jpg' onclick='dislike(\"".$_SESSION['user_name']."\",".$row['id_content'].")'/>";
                   echo"<input class='total_dislike_class' type='text' disabled='disabled' id='total_dislike_".$row['id_content']."' />";
                  
     }

}
mysql_close();
?>
